#!/bin/bash
#
# fbsplash wrapper script for Arch Linux splash hooks
#

source /sbin/splash-functions.sh
source /etc/conf.d/fbsplash.conf

#hooks
case "$1" in
	done)
		var_load RC_MULTI
		if [ ${SPLASH_RC_MULTI} = 0 ] 2> /dev/null
		then
			var_load STEP_NR MAX_STEPS
			((SPLASH_STEP_NR++))
			SPLASH_PROGRESS=$((100*${SPLASH_STEP_NR}/${SPLASH_MAX_STEPS}))
			SPLASH_CURRENT_PROGRESS=${SPLASH_PROGRESS}
			splash_progress ${SPLASH_PROGRESS}
			var_save STEP_NR CURRENT_PROGRESS
		fi
	;;

	init)
		cache_prepare
		splash_setup
		SPLASH_DAEMON_STEPS=$(count_daemon_steps)
		SPLASH_MAX_STEPS=$(($(count_sysinit_steps)+${SPLASH_DAEMON_STEPS}))
		SPLASH_STEP_NR=0
		SPLASH_RC_MULTI=0
		var_save MAX_STEPS STEP_NR RC_MULTI DAEMON_STEPS
	;;

	multi_startup)
		SPLASH_STEP_NR=0
		SPLASH_RC_MULTI=1
		var_save STEP_NR RC_MULTI
	;;

	multi_progress)

		var_load CURRENT_PROGRESS STEP_NR DAEMON_STEPS
		((SPLASH_STEP_NR++))
		SPLASH_PROGRESS=$((${SPLASH_CURRENT_PROGRESS}+$((100-${SPLASH_CURRENT_PROGRESS}))*${SPLASH_STEP_NR}/${SPLASH_DAEMON_STEPS}))
		splash_progress ${SPLASH_PROGRESS}
		var_save STEP_NR
	;;

	exit)
		splash_exit
		cache_remove
	;;

	verbose)
		splash_verbose
	;;

	fail)
		splash_verbose
	;;

	*)
	;;
esac
exit 0

#EOF
